package cn.xiaobai.controller;

import cn.xiaobai.enums.StateEnum;
import cn.xiaobai.service.HolidayAnalyzeService;
import cn.xioabai.common.domain.ResultDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Author yangdaji
 * @Date 2023/8/13
 * @PackageName cn.xiaobai.controller
 * @ClassName HolidayAnalyzeController
 */
@RestController
public class HolidayAnalyzeController {


    @Autowired
    private HolidayAnalyzeService holidayAnalyzeService;

    @RequestMapping(value = "/jiari", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultDTO<Object> jiari(@RequestParam(value = "d", required = false) String date) {
        Object result;
        String[] daySplit = date.split(",");
        if (daySplit.length > 1) {
            List<String> dayList = Arrays.asList(daySplit);
            result = holidayAnalyzeService.queryMultiDateHoliday(dayList);
            return ResultDTO.success(result);
        } else if (daySplit.length == 1 && StringUtils.isNoneBlank(date)) {
            result = holidayAnalyzeService.queryDateHoliday(date);
            return ResultDTO.success(StateEnum.getExplain((Integer) result), result);
        }

        return ResultDTO.error(StateEnum.getExplain(StateEnum.Unknown.getState()), null);
    }
}
